<template>
  <div class="problem-answer-tab">
    <div class="answer-content">
      <div class="answer-header">
        <h3>题目答案</h3>
        <a-tag color="green" v-if="questionData?.answer">
          <check-circle-outlined />
          官方答案
        </a-tag>
      </div>
      
      <div class="answer-section" v-if="questionData?.answer">
        <div class="answer-text">
          <div class="answer-description" v-html="questionData.answer"></div>
        </div>
      </div>
      
      <div class="no-answer" v-else>
        <div class="no-answer-icon">
          <question-circle-outlined />
        </div>
        <div class="no-answer-text">
          <h4>暂无官方答案</h4>
          <p>该题目暂时没有提供官方答案，请尝试自己解决或查看其他用户的提交记录。</p>
        </div>
      </div>

      <!-- 解题思路提示 -->
      <div class="hints-section" v-if="questionData?.answer">
        <h4>解题提示</h4>
        <div class="hints-list">
          <div class="hint-item">
            <div class="hint-icon">💡</div>
            <div class="hint-text">仔细阅读题目描述，理解输入输出格式</div>
          </div>
          <div class="hint-item">
            <div class="hint-icon">🔍</div>
            <div class="hint-text">分析示例，找出输入输出之间的规律</div>
          </div>
          <div class="hint-item">
            <div class="hint-icon">⚡</div>
            <div class="hint-text">考虑时间复杂度和空间复杂度的优化</div>
          </div>
          <div class="hint-item">
            <div class="hint-icon">🧪</div>
            <div class="hint-text">编写代码前先在纸上验证算法逻辑</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { CheckCircleOutlined, QuestionCircleOutlined } from '@ant-design/icons-vue'

interface Props {
  questionData?: API.Question
}

const props = defineProps<Props>()
</script>

<style scoped>
.problem-answer-tab {
  height: 100%;
  overflow-y: auto;
}

.answer-content {
  padding: 20px 24px;
}

.answer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.answer-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #1f1f1f;
  margin: 0;
}

.answer-section {
  margin-bottom: 32px;
}

.answer-text {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  border-left: 4px solid #52c41a;
}

.answer-description {
  line-height: 1.8;
  color: #333;
  font-size: 15px;
}

.answer-description :deep(p) {
  margin-bottom: 12px;
}

.answer-description :deep(code) {
  background: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 13px;
  color: #d63384;
  border: 1px solid #e9ecef;
}

.answer-description :deep(pre) {
  background: #fff;
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 13px;
  border: 1px solid #e9ecef;
  margin: 12px 0;
}

.no-answer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.no-answer-icon {
  font-size: 48px;
  color: #d9d9d9;
  margin-bottom: 16px;
}

.no-answer-text h4 {
  font-size: 18px;
  color: #666;
  margin-bottom: 8px;
}

.no-answer-text p {
  color: #999;
  line-height: 1.6;
  max-width: 400px;
}

.hints-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid #f0f0f0;
}

.hints-section h4 {
  font-size: 16px;
  font-weight: 600;
  color: #1f1f1f;
  margin-bottom: 16px;
}

.hints-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hint-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  background: #fff7e6;
  border-radius: 6px;
  border-left: 3px solid #faad14;
}

.hint-icon {
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 2px;
}

.hint-text {
  color: #666;
  line-height: 1.5;
  font-size: 14px;
}

/* 自定义滚动条 */
.problem-answer-tab::-webkit-scrollbar {
  width: 6px;
}

.problem-answer-tab::-webkit-scrollbar-track {
  background-color: #f1f1f1;
  border-radius: 3px;
}

.problem-answer-tab::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
  border-radius: 3px;
}

.problem-answer-tab::-webkit-scrollbar-thumb:hover {
  background-color: #a8a8a8;
}
</style>
